﻿DROP TRIGGER IF EXISTS  `pk_dynamic_log`; 
CREATE   TRIGGER  `pk_dynamic_log` AFTER INSERT ON  `open_dynamic`
  FOR EACH ROW BEGIN 

dECLARE pkf varchar(50) DEFAULT "";

sELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="dynamic";

if pkf <> "dynamic" then

  INSERT INTO open_pk_log SET pk_from = 'dynamic', pk_id = NEW.dy_id;

eLSE

   update open_pk_log SET pk_id = NEW.dy_id WHERE pk_from = 'dynamic';

end if;

end;